# -*- coding:utf-8 -*-
# @Time: 2021/1/12 12:01
# @Author: 周铖鑫
# @Description：张量与数据类型
# @File: main.py
import torch
import  numpy as np
x=torch.rand(2,3)#均匀分布
y=torch.randn(2,3)#正态分布
z1=torch.zeros(2,5)
z2=torch.ones(2,3,3)
x1=torch.tensor([2,3],dtype=torch.float32)
x2=x1.type(torch.int64)
print(x1)
print(x2)
print(x)
print(y)
print(z1)
print(z2)
print(z2.size())
print(z2.size(0))
print(z2.shape)
'''tensor和ndarray类型转换'''
a=np.random.randn(2,3)
print(a)
a1=torch.from_numpy(a)
print(a1)
print(a1.numpy())

'''张量的运算'''
d1=torch.rand(2,3)
d2=torch.rand(2,3)
print(d1)
print(d2)
print(d1+d2)#d1.add(d2)
d1.add_(d2)
print("现在的d1：{}".format(d1))
print(d2.shape)
print(d2.view(-1,1))
print("d2 sum:{}    d2 mean:{}".format(d2.sum(),d2.mean()))
#将tensor转化为item类型
d2_1=d2.sum().item()
print(d2_1)